import { Component, OnInit } from '@angular/core';
import { MonthWorkService } from './monthwork.service';
import { LocalStorage } from '@core/local.storage';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-monthworkarea',
  templateUrl: './monthworkarea.component.html',
  styleUrls: ['./monthworkarea.component.less'],
  providers: [MonthWorkService]
})
export class MonthworkareaComponent implements OnInit {
  queryData_gq: any;
  queryData_cj: any;
  queryData_dd: any;
  lockHeadScroll = { y: window.innerHeight - 350 + 'px' };
  showPage1 = true;
  showPage2 = false;
  tabIndex = 0;
  page2Param: any = {};
  userInfo = JSON.parse(this.ls.get('loginInfo'));
  userType = '';
  ddType: any;
  ddTypeName: any = {
    gcs: '段月计划',
    jskz: '段月计划',
    dz: '段月计划',
    qzbh: '段月计划',
    // jskz:'技术科科长',
    // dz:'段长'
  };
  cjList: any = [];
  showCjlist = true;
  // isTj = '';

  constructor(
    private activatedRoute: ActivatedRoute,
    private monthWorkService: MonthWorkService,
    private ls: LocalStorage
  ) { }

  ngOnInit() {
    this.activatedRoute.params.subscribe(params => {
      if (params && params.type) {
        this.ddType = params.type;
      }
    })
    this.initUserType();
  }

  initUserType() { 
    switch (this.userInfo.N_LEVEL) {
      case 10:
        this.userType = 'gq';
        this.queryData_gq = { orgtype: 'gq' };
        break;
      case 30:
        this.userType = 'cj';
        this.queryData_cj = { orgtype: 'cj' };
        this.queryData_gq = { orgtype: 'gq' };
        break;
      case 50:
        this.userType = 'dd';
        this.queryData_dd = { orgtype: this.ddType };
        this.queryData_cj = { orgtype: 'cj' };
        this.queryData_gq = { orgtype: 'gq' };
        this.getCj();
        break;
    }
  }

  getCj() {
    this.monthWorkService.getCjList().subscribe(res => {
      this.cjList = res;
    })
  }

  trDbclick(row) {
    this.showPage(2);
    this.page2Param = row;
    if (this.ddType) {
      this.page2Param.orgtype = this.ddType;
    }
  }

  showPage(num) {
    switch (num) {
      case 1:
        this.showPage1 = true;
        this.showPage2 = false;
        break;
      case 2:
        this.showPage1 = false;
        this.showPage2 = true;
        break;
    }
  }

  cjDbclick(row) {
    this.showGq(row);
  }

  showCj() {
    this.showCjlist = true;
  }
  showGq(row) {
    this.showCjlist = false;
    this.queryData_gq.cjorg = row.opValue;

  }

  tabSelectChange(e) {
    const tabCfg = {
      cj: [this.queryData_cj, this.queryData_gq],
      dd: [this.queryData_dd, this.queryData_cj, this.queryData_gq],
    };
    const paramCfg = {
      cj: ['cj', 'gq'],
      dd: ['dd', 'cj', 'gq'],
    }
    this[`queryData_${paramCfg[this.userType][e.index]}`] = JSON.parse(JSON.stringify(tabCfg[this.userType][e.index]));
  }
}
